#include <iostream>
#include <vector>

using namespace std;

class Solution {
  public:
    int numberOfAlternatingGroups(vector<int> &colors) {
        int len = colors.size(), cnt = 0;
        for (int i = 0; i < len; i++) {
            cnt += (colors[(len + i - 1) % len] == colors[(len + i + 1) % len] && colors[i] != colors[(len + i - 1) % len]);
        }
        return cnt;
    }
};